//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package cn.nubia.admin.application.controller;

import cn.nubia.admin.application.bean.SoftRecRank;
import cn.nubia.admin.application.query.SoftRecRankQuery;
import cn.nubia.admin.application.service.SoftRecRankService;
import cn.nubia.admin.application.service.SoftService;
import cn.nubia.admin.common.mybatis.bean.Paged;
import cn.nubia.admin.common.springmvc.Response;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

/**
 * create by gcj on 2015-09-12
 * 运营推荐管理类
 */
@Controller
@RequestMapping({"/admin/softRecRank/"})
public class SoftRecRankController {
    @Autowired
    private SoftRecRankService softRecRankService;

    @RequiresPermissions({"soft:rec:softrecranklist"})
    @RequestMapping({"softRecRankList"})
    public ModelAndView getSoftRecRankList(SoftRecRankQuery softRecRankQuery) {
        ModelAndView modelAndView = new ModelAndView("/recrank/softRecRankList");
        Paged softRecRankPage = this.softRecRankService.findPage(softRecRankQuery);
        modelAndView.addObject("softRecRankList", softRecRankPage);
        modelAndView.addObject("query", softRecRankQuery);
        return modelAndView;
    }

    @ResponseBody
    @RequestMapping(
            value = {"saveSoftRecRank"},
            method = {RequestMethod.POST}
    )
    public Response<String> save(SoftRecRank softRecRank) {
        return Response.getSuccessResponse(this.softRecRankService.save(softRecRank));
    }

    @RequestMapping(
            value = {"viewSoftRecRank"},
            method = {RequestMethod.GET}
    )
    public ModelAndView view(Integer softRecRankId, String origin) {
        ModelAndView modelAndView = new ModelAndView("/recrank/recRankFrom");
        SoftRecRank softRecRank = new SoftRecRank();
        if(softRecRankId != null) {
            softRecRank = this.softRecRankService.get(softRecRankId);
        }

        modelAndView.addObject("origin", origin);
        modelAndView.addObject("softMap", softRecRank);
        modelAndView.addObject("softRecRankId", softRecRankId);
        return modelAndView;
    }

    @RequestMapping(
            value = {"addSoftRecRank"},
            method = {RequestMethod.GET}
    )
    public ModelAndView addViewSoft(Integer softId, String origin) {
        ModelAndView modelAndView = new ModelAndView("/recrank/recRankFrom");
        SoftRecRank softRecRank = new SoftRecRank();
        if(softId != null && !"".equals(softId)) {
            softRecRank.setSoftId(softId);
        }

        modelAndView.addObject("origin", origin);
        modelAndView.addObject("softMap", softRecRank);
        modelAndView.addObject("softRecRankId", "");
        return modelAndView;
    }

    @ResponseBody
    @RequestMapping(
            value = {"deleteSoftRecRank"},
            method = {RequestMethod.POST}
    )
    public Response<Boolean> delete(Integer softRecRankId) {
        this.softRecRankService.changeSoftRecRank(softRecRankId, Integer.valueOf(-1));
        return Response.getSuccessResponse(Boolean.valueOf(true));
    }

    @ResponseBody
    @RequestMapping(
            value = {"changeSoftRecRank"},
            method = {RequestMethod.POST}
    )
    public Response<Boolean> changeSoftRecRank(Integer softRecRankId, Integer state) {
        this.softRecRankService.changeSoftRecRank(softRecRankId, state);
        return Response.getSuccessResponse(Boolean.valueOf(true));
    }
}
